// +build !go1.7

package log

import (
	"runtime"
	"strings"

	"xp/lib/jsonx"
)

func writeCallers(pcs []uintptr, buf []byte) int {
	var i int
	for ii, pc := range pcs {
		fn := runtime.FuncForPC(pc)
		if fn != nil {
			if ii != 0 {
				i += copy(buf[i:], ",")
			}
			file, line := fn.FileLine(pc)
			index := strings.Index(file, "xp/")
			if index > 0 {
				i += copy(buf[i:], file[index+4:])
				i += copy(buf[i:], ":")
				i += jsonx.FormatBits(buf[i:], uint64(line), line < 0)
			}
		}
	}
	return i
}
